class HashTable {
  constructor() {
    this.table = new Array(18)
  }

  hashFn(data) {
    let count = 0
    for(let i = 0; i < data.length; ++i) {
      count += data.charCodeAt(i)
    }
    return count % this.table.length
  }

  put(data) {
    const pos = this.hashFn(data)
    this.table[pos] = data
  }

  printAll() {
    this.table.forEach((item, index) => {
      if(item !== undefined) console.log("key: " + index + "\tvalue:" + item)
    })
  }
}

const names = ['zhang1', 'zhang2', 'zhang3', 'zhang4', 'zhang5', 'zhang6']

const table = new HashTable()

names.forEach(item => {
  table.put(item)
})

table.printAll()
